#ifndef WIJIUISCRIPTABLE_H
#define WIJIUISCRIPTABLE_H

#include <QObject>
#include <QProcess>
#include <QList>
#include <QtGui/QMainWindow>
#include "WijiDialog.h"
#include "WijiRPC.h"
#include "WijiDOM.h"
#include "scripter.h"
//This class is a proxy for manipulating WijiUi from within scripts, and in the future, via the socket server.
// All functionality that is to be made available outside of Wiji should move through this point for error checking
// and validation.
class WijiUiScriptable : public QObject
{
Q_OBJECT
public:
    explicit WijiUiScriptable(QObject *parent = 0);
    QProcess process;
    static WijiUiScriptable* _self;
    static WijiUiScriptable* getSelf() {
        if (!_self) {
            _self = new WijiUiScriptable();
         }
        return _self;
    };
    WijiDOM dom;
    Scripter scripter;

private:
    QList<WijiDialog*> dialogs;
    QProcess* runInteractiveProgram(QString line, QString csvArgs);
    QString readFromInteractiveProgram(QProcess* p);
signals:

public slots:
    //This is essentially the scripting API, the standards are:
    // As few args as possible.
    // camelCase with the first letter dc.
    // try to be descriptive, like fileGetContents and filePutContents.
    // Think before you add, can this functionality be implemented by extending
    // wiji in QtScript?
    void close();
    QString fileGetContents(QString filename);
    QString parseHtml(QString html);
    QString parseFile(QString filename);
    bool filePutContents(QString filename,QString contents, bool urlEncoded);
    bool notify(QString title, QString message);
    bool navigateTo(QString);
    QString getIniValue(QString key);
    QString readFromProgram(QString line);
    int newDialog(QString url, int width = 200, int height = 100);
    bool destroyDialog(int index);
    bool resizeDialog(int index,int width, int height);
    bool setDialogUrl(int index,QString url);
    bool consoleLog(QString text);
    bool setMainWindowSize(int width,int height);
    QString testServer(QString message);
    QString getElementById(QString id);
    QString getContentOfElementById(QString id);
    bool replaceElement(QString id, QString content);
    QString saveFileDialog(QString title, QString path, QString fileHint);
    QString openFileDialog(QString title, QString path);
    QString openFilesDialog(QString title, QString path);
    bool setMainWindowHtml(QString content, QString url);
};

#endif // WIJIUISCRIPTABLE_H
